package com.bilibili.juc.volatiles;

import java.util.concurrent.TimeUnit;

public class TestVolatile {
    private volatile boolean flag = true;

    public void m() {
        System.out.println("m start");
        while (flag) {
        }
        System.out.println("m end");
    }

    public static void main(String[] args) throws Exception {
        TestVolatile test = new TestVolatile();
        new Thread(() -> test.m()).start();

        TimeUnit.SECONDS.sleep(1);

        test.flag = false;
    }
}

//https://mp.weixin.qq.com/s/38oj6avOz4M0TiT6BhYSgw